package com.sf.dlb.web.service;

import com.sf.dlb.constant.CacheConstant;
import com.sf.dlb.jpa.model.*;
import com.sf.dlb.jpa.repository.*;
import com.sf.dlb.utils.*;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * Created by jing.tan on 2018/12/10.
 */
@Service
public class UserInfoService {
    private static Logger logger= LoggerFactory.getLogger(UserInfoService.class);
    @Autowired
    public RedisUtil redisUtil;

    /**
     * 禁止登陆的用户列表
     * @return
     */
    public List<String> userForbidList(){
        List<String> forbidList=new ArrayList<>();
        String key=CacheConstant.USER_CACHE+CacheConstant.BAN_USER_3DAY_LOGIN;
        Set<String> setList= (Set) redisUtil.sGet(key);
        for (String userId:setList) {
            String userIdKey=CacheConstant.USER_CACHE+CacheConstant.BAN_USER_3DAY_LOGIN+userId;
            boolean existFlag=redisUtil.hasKey(userIdKey);
            if(existFlag){
                forbidList.add(userId);
            }else{
                redisUtil.setRemove(key,userId);
            }
        }
        logger.info("userForbidList forbidList={}",forbidList.size());
        return forbidList;
    }
}
